Repository navigation
fix(ShaderConverter): read the subprograms of 2021.2+ shader blobs - #385
Open
nichinichisou0609 wants to merge 2 commits into
Open
nichinichisou0609 wants to merge 2 commits into
nichinichisou0609 wants to merge 2 commits into
Conversation
…erenced Since Unity 2021.2 (record version 202012090) a platform's shader blob holds parameter records next to the subprogram records. The two have different layouts, and only the parsed form tells them apart. ShaderProgram parsed every index entry as a subprogram, so a parameter record had its leading fields read as a keyword count and keyword strings, and the export failed with struct.error past the end of the blob. Among Unity's built-in shaders, UI/DefaultETC1 and Hidden/VideoDecode in a 2022.3 player build fail this way. ShaderProgram now keeps the index table and reads a record only when it is requested through get_subprogram(), which replaces the eagerly filled m_SubPrograms list.
nichinichisou0609
force-pushed
the
codex/shader-segments
branch
from
November 16, 2026 12:44
00dabe1 to
c6e9d91
Compare
Contributor
Author
|
Same as in #384/#391: removed the test module and rebased on master. While checking this against real 2022.3 data I found that these shaders also fail for a second reason, in the same function, so I added it here as a second commit instead of opening another PR on top of this one. The description explains both. Happy to split it out if you prefer. Both fixes have a sample in the zip, built from an empty Unity 2022.3 project (the build script and shader generator are included). The README lists which commit each one needs. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two problems in how
ShaderProgramreads a platform's compressed blob, one commit each. Both makeShader.export()raisestruct.error.Multi-segment blobs. From Unity 2019.3 a blob can be split into segments, each compressed separately, and every entry of the index table names the segment its record is in. Export only decompressed segment 0 and read every offset from it, so a record in segment 1 or 2 was read from the wrong bytes or past the end. Every segment is now decompressed, and each entry is read at its offset inside the segment it names (older entries have no segment field and use segment 0). Single-segment shaders work as before, the two-argument
ShaderProgramconstructor is kept, and mismatched segment arrays or a reference to a missing segment raiseValueError.For reference, AssetStudio decompresses each segment separately and reads each entry at its offset inside the referenced segment.
Parameter records. Since Unity 2021.2 the index table also points at parameter records, which have a different layout from subprogram records and are only told apart through the parsed form.
ShaderProgramparsed every entry as a subprogram up front, so a parameter record was read as keywords and strings until it ran off the end.ShaderProgramnow keeps the index table and reads a record only when a subprogram asks for it, throughget_subprogram(index); this replaces the eagerly filledm_SubProgramslist. Among Unity's own shaders this hitsUI/DefaultETC1andHidden/VideoDecodein a 2022.3 player build.Samples (attached, built with Unity 2022.3.62f2):
shader_segments: one shader, GLES3 blob in 3 segmentsunity_builtin_extraof a Windows player, 42 shadersNot changed here: in 2021.2+ player builds the passes reference their programs through
m_PlayerSubProgramsrather thanm_SubPrograms, so the exported text of those shaders still has no program code, as on master.